/****************************************************************
 ** Product  :   HP Subscriber Network Application Policy
 ** Module   :   gr-manager
 ** Date: Apr 10, 2015               
 ** Author: Huang xiaoji
 ** (C) Copyright 2015, Hewlett-Packard Company, All Rights Reserved.
 ** This software is the proprietary information of HP, Inc.  
 ** Use is subject to license terms.
 *****************************************************************
 ** Description:   
 **    Collect the status info for SGR and show in console by specific format.
 **    
 ****************************************************************/
package com.hp.snap.gr.action.impl;

import com.hp.snap.gr.exception.ActionException;
import com.hp.snap.gr.model.ReplicatorStatusInfo;
import com.hp.snap.gr.model.jaxb.ActionType;
import com.hp.snap.gr.model.jaxb.GeneralActionType;
import com.hp.snap.gr.utils.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 
 * Collect the status info for SGR and show in console by specific format.The SGR status from action output.
 * 
 * There are no parameter can be configured in the action.
 *
 * From action output to get SGR status
 *   _REPLICATOR_STATUS_INFO: local replicator status info.
 *   _REPLICATOR_REMOTE_STATUS_INFO: remote replicator status info.
 * 
 * <P>
 * Version: 3.3 <br>
 * Author: Huang xiaoji 
 * Date: Apr 10, 2015
 * 
 * </P>
 * 
 **/
public class ShowReplicatorStatusInfoActionHandler extends AbstractActionHandler {
    private static final Logger logger = LoggerFactory.getLogger(ShowReplicatorStatusInfoActionHandler.class);

    @Override
    public void execute(ActionType action, Map<String, Object> actionPlanInputs, Map<String, Object> actionPlanOutputs) throws ActionException {

        if (action instanceof GeneralActionType) {
            ReplicatorStatusInfo statusInfo = (ReplicatorStatusInfo) actionPlanOutputs.get(Constants.REPLICATOR_STATUS_INFO);
            ReplicatorStatusInfo remoteInfo = (ReplicatorStatusInfo) actionPlanOutputs.get(Constants.REPLICATOR_REMOTE_STATUS_INFO);

            Constants.CONSOLE.info("==================== SGR Status Information ====================");
            Constants.CONSOLE.info("Local Newest Files:");

            if (statusInfo != null) {
                Constants.CONSOLE.info("\tFileName: {}", statusInfo.getFileName());
                Constants.CONSOLE.info("\tFileSize: {} bytes", statusInfo.getFileSize());
                Constants.CONSOLE.info("\tCreatedTime: {}", statusInfo.getCreatedTime());
            } else {
                Constants.CONSOLE.info("\tWarning: Export file have not created yet.");
            }
            Constants.CONSOLE.info("");
            Constants.CONSOLE.info("Remote Newest Files:");
            if (remoteInfo != null) {
                Constants.CONSOLE.info("\tFileName: {}", remoteInfo.getFileName());
                Constants.CONSOLE.info("\tFileSize: {} bytes", remoteInfo.getFileSize());
                Constants.CONSOLE.info("\tCreatedTime: {}", remoteInfo.getCreatedTime());
            } else {
                Constants.CONSOLE.info("\tWarning: Remote replicator status get failed.");
            }
            Constants.CONSOLE.info("====================          End          ====================");
        }
    }
}
